package com.hualan.sfzyproject.controller;

import com.hualan.sfzyproject.domain.ChatMessageDTO;
import com.hualan.sfzyproject.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private ChatService chatService;

    @GetMapping("/list")
    public ResponseEntity<?> getConsultantChatList(@RequestParam String consultantId) {
        List<ChatMessageDTO> chatList = chatService.getConsultantChatList(consultantId);
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", chatList);
        return ResponseEntity.ok(response);
    }

    @GetMapping("/history")
    public ResponseEntity<?> getChatHistory(
        @RequestParam String consultantId,
        @RequestParam String userId
    ) {
        List<ChatMessageDTO> history = chatService.getChatHistory(consultantId, userId);
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", history);
        return ResponseEntity.ok(response);
    }
}